import React from 'react';
import { WeaInputLocale, WeaLocaleProvider } from 'ecCom';

const getCurrentLabel = WeaInputLocale.getCurrentLabel;
const getLabel = WeaLocaleProvider.getLabel;
export default class ApiShowBase extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
    };
  }

    render = () => (
      <div>
        <div className="api_tableName section-title">
          <strong>{getLabel(1361, '基本信息')}</strong>
        </div>
        <div className="api_table">
          {this.getBase()}
        </div>
      </div>
    )
    getBase() {
      const { baseList } = this.props;
      const show = [];
      let double = [];
      baseList.map((base, index) => {
        if (getCurrentLabel(base.value).match(/；/)) {
          getCurrentLabel(base.value).replace(/；/g, ';<br>');
        }
        // 如果值的长度为30以下，就用两列显示
        if (getCurrentLabel(base.value).length < 30) {
          if (double.length == 0) {
            double.push(
              <div className="api_base_table_row">
                <div className="api_tdName">{getCurrentLabel(base.showName)}</div>
                <div className="api_tdValue">{getCurrentLabel(base.value)}</div>
              </div>,

            );
          } else if (double.length == 1) {
            double.push(
              <div className="api_base_table_row">
                <div className="api_tdName">{getCurrentLabel(base.showName)}</div>
                <div className="api_tdValue">{getCurrentLabel(base.value)}</div>
              </div>,

            );
          }
          // 一行数据为  名称|值|名称|值        如果最后一次数据只有 名称|值 也为一行显示
          if ((double.length >= 2) || (double.length == 1 && index == baseList.length - 1)) {
            show.push(
              double.map(d => d),
            );
            double = [];
          }
        } else {
          show.push(
            <div className="api_base_table_rowlong">
              <div className="api_tdName">{getCurrentLabel(base.showName)}</div>
              <div className="api_tdValue" dangerouslySetInnerHTML={{ __html: getCurrentLabel(base.value) }} />
            </div>,
          );
        }
      });
      return show;
    }
}
